import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/form")
public class FormParameterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 约定, 前端构造形如这样的请求:
        // POST /postParameter
        // Content-Type: x-www-form-urlencoded
        //
        // username=zhangsan&password=123

        // 编码规则不同就会出现乱码
        req.setCharacterEncoding("utf8");

        String name=req.getParameter("name");
        String password=req.getParameter("password");

        System.out.println("name=" + name);
        System.out.println("password=" + password);

        resp.setContentType("complication/x-www-form-urlencoded;charset=utf8");
        resp.getWriter().write("name= " + name+" "+"password= " + password+" "+"  ok");

    }
}
